package com.TIEmulator;

import android.app.Activity;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import com.TIEmulator.JNI.NLib;

public class OnScreenFKeys
{
  private static final View.OnTouchListener myClickListener = new View.OnTouchListener()
  {
    public boolean onTouch(View paramView, MotionEvent paramMotionEvent)
    {
      if (paramMotionEvent.getAction() == 0)
      {
        int i = paramView.getId();
        if (i > -1)
          NLib.postTIKeyCodeIdx(i);
      }
      return true;
    }
  };

  public static void Setup(View paramView, Activity paramActivity, int paramInt)
  {
    LinearLayout localLinearLayout = (LinearLayout)paramView;
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    paramActivity.getWindowManager().getDefaultDisplay().getMetrics(localDisplayMetrics);
    int i = (int)(32.0F * localDisplayMetrics.density);
    int j = (int)(20.0F * localDisplayMetrics.density);
    String[] arrayOfString = new String[9];
    arrayOfString[0] = "F1";
    arrayOfString[1] = "F2";
    arrayOfString[2] = "F3";
    arrayOfString[3] = "F4";
    arrayOfString[4] = "F5";
    arrayOfString[5] = "F6";
    arrayOfString[6] = "F7";
    arrayOfString[7] = "F8";
    arrayOfString[8] = "ESC";
    int[] arrayOfInt1 = new int[9];
    arrayOfInt1[0] = 517;
    arrayOfInt1[1] = 518;
    arrayOfInt1[2] = 519;
    arrayOfInt1[3] = 520;
    arrayOfInt1[4] = 521;
    arrayOfInt1[5] = 522;
    arrayOfInt1[6] = 523;
    arrayOfInt1[7] = 524;
    arrayOfInt1[8] = 27;
    int[] arrayOfInt2 = NLib.transcodeCodeIdx(arrayOfInt1, arrayOfInt1.length);
    if (paramInt == -1)
      arrayOfInt1.length;
    for (int k = 0; ; ++k)
    {
      if (k >= arrayOfInt1.length)
        return;
      Button localButton = new Button(paramActivity);
      localButton.setText(arrayOfString[k]);
      localButton.setId(arrayOfInt2[k]);
      localButton.setBackgroundResource(2130837535);
      localButton.setOnTouchListener(myClickListener);
      localButton.setFocusable(false);
      localButton.setFocusableInTouchMode(false);
      localButton.setWidth(i);
      localButton.setHeight(j);
      localLinearLayout.addView(localButton);
    }
  }
}
